<?php 
/**
 * 向JS端返回统一格式的评论
 * @version $Id: js_format_comment.func.php 10883 2012-03-02 05:39:58Z yaoying $
 * @param array $comment 单条评论信息
 * @param bool $nl2br 对评论内容分行？默认否
 * @return array
 */
function js_format_comment($comment, $nl2br = false){
    $return = array();
   	if(is_array($comment['user'])){
		$user =& $comment['user'];
	}else{
		$user = array(
		    'id' => 0, 'faxe_m' => '', 'nickname' => '无名氏', 'level' => 0,
		);
	}
	$return['id'] = (string)$comment['id'];
	$comment['text'] = htmlspecialchars($comment['text']);
	if(isset($comment['to_user']['id']) && $comment['to_user']['id'] > 0){
		$return['text'] = preg_replace("/@([^:]+)/","<a href=\"".URL('space.ta',array('id'=>$comment['to_user']['id']))."\">$1</a>",$comment['text']);
	}else{
		$return['text'] = $comment['text'];
	}
	if($nl2br){
		$return['text'] = F::nl2br($return['text']);
	}	
	$return['text'] = F::emExchange($return['text']);
	$return['create_at'] = F::wb_time($comment['create_time']);
	$return['nick'] = $user['nickname'];
	$return['uid'] = (string)$user['id'];
	$return['profileImg'] = $user['face_m'];
	$return['level'] =$user['level'];		
	$return['user']['v'] = 0;
	$return['ext'] = $comment['ext'];
	$return['user']['profileUrl'] = URL('space.ta', array('id'=>"{$user['id']}"));
	
	return $return;
}